﻿/**
    This file is part of GDkit.

    GDkit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3 of the License.

    GDkit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with GDKit.  If not, see <http://www.gnu.org/licenses/>.
	
    Author: Lahiru Lakmal Priyadarshana <llahiru@gmail.com>
**/

var ani = null;
var main_obj = img_main;
var val_dur = 3000;
var val_rot = 0;
var m_x = 0;
var m_y = 0;

function view_onOpen() {
	ani = new Animation(main_obj);
}

function init() {
	val_dur = tbox_dur.value;
	val_rot = tbox_rotation.value;
	m_x = tbox_x.value;
	m_y = tbox_y.value;

	if(val_dur.match(/^\d+$/) && val_rot.match(/^\d+$/) && m_x.match(/^\d+$/) && m_y.match(/^\d+$/)) {
		return true;
	} else {
		reset();
		return false;
	}
}

function b_reset_onclick() {
	main_obj.width = 100;
	main_obj.height = 100;
	main_obj.x = 80;
	main_obj.y = 80;
	main_obj.rotation = 0;
	main_obj.opacity = 255;
	tbox_x.value = 80;
	tbox_y.value = 80;
}

function doFade() {
	switch (cmb_f.selectedIndex) {
		case 0:
			return false;
			break;
		case 1:
			eval("ani.fadeIn();");
			break;
		case 2:
			eval("ani.fadeOut();");
	}
}

function doScale() {
	switch (cmb_s.selectedIndex) {
		case 0:
			return false;
			break;
		case 1:
			eval("ani.scaleIn();");
			break;
		case 2:
			eval("ani.scaleOut();");
	}
}

function b_animate_onclick() {
	if(init()) {
		ani.setDuration(val_dur);
		ani.rotate(val_rot);
		ani.moveX("",m_x);
		ani.moveY("",m_y);
		doFade();
		doScale();
	}
	else {
		alert("Error in values entered!");
	}
}
